#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int hash[128] = { 0 };
        int n = s.size();
        int left = 0, right = 0, len = 0;
        int flag = 0;
        while (right < n)
        {
            hash[s[right]]++;
            while (hash[s[right]] > 1)
            {
                flag = 1;
                len = max(len, right - left);
                hash[s[left++]]--;
            }
            right++;
        }
        len = max(len, right - left);
        if (flag == 1)return len;
        else return n;
    }
};